package BIO.chat_demo;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

/**
 * 客户端:实现客户端上传任意类型的文件数据给服务端保存起来
 */
public class Client {
    public static void main(String[] args) {
        System.out.println("===========客户端启动=========");
        try {
            //1.创建Socket对象请求服务端连接
            Socket socket = new Socket("localhost",9999);
            //2.从管道中获取字节输出流
            OutputStream outputStream = socket.getOutputStream();
            //3.将字节输出流包装成一个打印流
            PrintStream ps = new PrintStream(outputStream);
            Scanner sc = new Scanner(System.in);
            while (true){
                System.out.print("请说:");
                String msg = sc.nextLine();
                ps.println(msg);
                ps.flush();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
